package com.ruoyi.web.controller.cms.nav;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysRole;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cms.navType.domain.CmsNavType;
import com.ruoyi.cms.navType.service.ICmsNavTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 菜单类别Controller
 *
 * @author linyang
 * @date 2025-07-28
 */
@RestController("AdminCmsNavTypeController")
@RequestMapping("/admin/cms/nav/type")
public class CmsNavTypeController extends BaseController {
    @Resource
    private ICmsNavTypeService cmsNavTypeService;

    /**
     * 查询菜单类别列表
     */
    //@PreAuthorize("@ss.hasPermi('cms:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsNavType cmsNavType) {
        startPage();
        List<CmsNavType> list = cmsNavTypeService.selectCmsNavTypeList(cmsNavType);
        return getDataTable(list);
    }

    /**
     * 导出菜单类别列表
     */
    //@PreAuthorize("@ss.hasPermi('cms:type:export')")
    @Log(title = "菜单类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsNavType cmsNavType) {
        List<CmsNavType> list = cmsNavTypeService.selectCmsNavTypeList(cmsNavType);
        ExcelUtil<CmsNavType> util = new ExcelUtil<CmsNavType>(CmsNavType.class);
        util.exportExcel(response, list, "菜单类别数据");
    }

    /**
     * 获取菜单类别详细信息
     */
    //@PreAuthorize("@ss.hasPermi('cms:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(cmsNavTypeService.selectCmsNavTypeById(id));
    }

    /**
     * 新增菜单类别
     */
    //@PreAuthorize("@ss.hasPermi('cms:type:add')")
    @Log(title = "菜单类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsNavType cmsNavType) {
        return toAjax(cmsNavTypeService.insertCmsNavType(cmsNavType));
    }

    /**
     * 修改菜单类别
     */
    //@PreAuthorize("@ss.hasPermi('cms:type:edit')")
    @Log(title = "菜单类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsNavType cmsNavType) {
        return toAjax(cmsNavTypeService.updateCmsNavType(cmsNavType));
    }

    /**
     * 删除菜单类别
     */
    //@PreAuthorize("@ss.hasPermi('cms:type:remove')")
    @Log(title = "菜单类别", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cmsNavTypeService.deleteCmsNavTypeByIds(ids));
    }


    /**
     * 状态修改
     */
    //@PreAuthorize("@ss.hasPermi('system:role:edit')")
    @Log(title = "角色管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody CmsNavType cmsNavType) {
        cmsNavType.setUpdateBy(getUsername());
        return toAjax(cmsNavTypeService.updateCmsNavTypeStatus(cmsNavType));
    }
}
